package com.hivekion.system.controller;

import com.hivekion.common.annotation.AutoLog;
import com.hivekion.common.enums.OperationTypeEnum;
import com.hivekion.system.domain.SysStatisticsBiName;
import com.hivekion.system.domain.SysStatisticsItemSchame;
import com.hivekion.system.domain.SysStatisticsTargetSum;
import com.hivekion.system.domain.vo.*;
import com.hivekion.system.service.ISysStatisticsBiSchameService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/statisticsBiSchame")
public class SysStatisticsBiShameController {
      @Autowired
      ISysStatisticsBiSchameService statisticsBiSchameService;

      //      @GetMapping("/getItemSelectList")
//      @AutoLog(value = "获取统计已选/未选项", operationType = OperationTypeEnum.SELECT, module = "系统管理/配置表管理")
//      public List<SysStatisticsItemSchameSelectViewVo> getItemSelectList(
//	      String biNameId, String type) {
//	    if (type.equals("select")) {
//		  return statisticsBiSchameService.getItemSchameList(biNameId);
//	    } else {
//		  return statisticsBiSchameService.getItemSchameSelectList(biNameId);
//	    }
//      }

      @ApiOperation(value = "获取自定义表单-统计项列表", notes = "系统管理/自定义统计表单配置")
      @GetMapping("/getItemSelectList")
      @AutoLog(value = "获取自定义表单-统计项列表", operationType = OperationTypeEnum.SELECT, module = "系统管理/自定义统计表单配置")
      public List<SysBiDataItemSchameVo> getItemSchameList(String biNameId) {
	    List<SysBiDataItemSchameVo> list = statisticsBiSchameService.getSettingItemSchameList(biNameId);
	    return list;
      }


      @PostMapping("/addItemSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:add')")
      @AutoLog(value = "新增统计项配置", operationType = OperationTypeEnum.INSERT, module = "系统管理/配置表管理")
      public boolean addItemSchame(@RequestBody SysStatisticsItemSchameCreateInputVo inputVo) {
	    return statisticsBiSchameService.createItemSchame(inputVo);
      }

      @GetMapping("/getItemSchameInfo")
      @AutoLog(value = "获取单个统计项配置", operationType = OperationTypeEnum.SELECT, module = "系统管理/配置表管理")
      public SysStatisticsItemSchame getItemSchameInfo(String itemSchameId) {
	    return statisticsBiSchameService.getItemInfo(itemSchameId);
      }

      ;

      @DeleteMapping("/removeItemSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:delete')")
      @AutoLog(value = "删除统计项配置", operationType = OperationTypeEnum.DELETE, module = "系统管理/配置表管理")
      public boolean deleteItemSchame(String itemSchameId) {
	    // TODO 需要删除 统计项和子项的所有数据
	    return statisticsBiSchameService.deleteItemSchame(itemSchameId);
      }

      @PostMapping("/checkNameUnique")
      public boolean checkNameUnique(String itemName, String itemId) {
	    return statisticsBiSchameService.checkItemSchameNameUnique(itemName, itemId);
      }

      //region 统计指标
      @ApiOperation(value = "新增统计指标", notes = "系统管理/自定义统计表单配置")
      @PostMapping("/addTargetSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:add')")
      @AutoLog(value = "新增指标配置项", operationType = OperationTypeEnum.INSERT, module = "系统管理/自定义统计表单配置")
      public boolean addTargetSchame(@RequestBody SysStatisticsTargetSchameCreateInputVo inputVo) {
	    return statisticsBiSchameService.createTargetSchame(inputVo);
      }

      @ApiOperation(value = "删除统计指标", notes = "系统管理/自定义统计表单配置")
      @DeleteMapping("/removeTargetSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:delete')")
      @AutoLog(value = "删除统计指标", operationType = OperationTypeEnum.DELETE, module = "系统管理/自定义统计表单配置")
      public boolean deleteTargetSchame(String targetSchameId) {
	    return statisticsBiSchameService.deleteTargetSchame(targetSchameId);
      }

      @ApiOperation(value = "编辑统计指标", notes = "系统管理/自定义统计表单配置")
      @PutMapping("/editTargetSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:edit')")
      @AutoLog(value = "编辑统计指标", operationType = OperationTypeEnum.UPDATE, module = "系统管理/自定义统计表单配置")
      public boolean editTargetSchame(@RequestBody SysStatisticsTargetSchameUpdateVo vo) {
	    return statisticsBiSchameService.editTargetSchame(vo);
      }

      /*
       * 2022-1-2 弃用
       * */
      @ApiOperation(value = "2022-1-2 弃用", notes = "2022-1-2 弃用")
      @GetMapping("/getTargetSelectList")
      @AutoLog(value = "获取统计表单-统计指标列表", operationType = OperationTypeEnum.SELECT, module = "系统管理/自定义统计表单配置")
      public List<SysStatisticsTargetSchameViewVo> getTargetSelectList(
	      String biNameId, String targetType, String type) {
//	    if (type.equals("select")) {
//		  return statisticsBiSchameService.getTargetSchameList(biNameId, targetType);
//	    } else {
//
//	    }
	    return statisticsBiSchameService.getTargetSchameList(biNameId);
      }

      @ApiOperation(value = "获取统计指标列表", notes = "系统管理/自定义统计表单配置")
      @GetMapping("/getTargetSchameList")
      @AutoLog(value = "获取统计表单-统计指标列表", operationType = OperationTypeEnum.SELECT, module = "系统管理/自定义统计表单配置")
      public List<SysStatisticsTargetSchameViewVo> getTargetSchameList(
	      String biNameId) {
	    return statisticsBiSchameService.getTargetSchameList(biNameId);
      }

      @ApiOperation(value = "获取统计指标", notes = "系统管理/自定义统计表单配置")
      @GetMapping("/getTargetSchameInfo")
      @AutoLog(value = "获取统计指标配置信息", operationType = OperationTypeEnum.SELECT, module = "系统管理/自定义统计表单配置")
      public SysStatisticsTargetSchameModelVo getTargetSchameInfo(String key) {
	    return statisticsBiSchameService.getTargetSchameInfo(key);
      }

      @PostMapping("/getTargetSumSchameList")
      @AutoLog(value = "获取计算指标配置列表", operationType = OperationTypeEnum.SELECT, module = "系统管理/配置表管理")
      public List<SysStatisticsTargetSumSchameSelectViewVo> getTargetSumSchameList(String biNameid) {
	    return statisticsBiSchameService.getTargetSumSchameList(biNameid);
      }

      //endregion


      @PostMapping("/addTargetSumSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:add')")
      @AutoLog(value = "新增计算指标配置项", operationType = OperationTypeEnum.INSERT, module = "系统管理/配置表管理")
      public boolean addTargetSumSchame(
	      @RequestBody SysStatisticsTargetSumSchameCreateInputVo inputVo) {
	    boolean ok = statisticsBiSchameService.addTargetSum(inputVo);
	    return ok;
      }

      @PostMapping("/addTargetCollectSumSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:add')")
      @AutoLog(value = "新增汇总计算指标", operationType = OperationTypeEnum.INSERT, module = "系统管理/配置表管理")
      public boolean addTargetCollectSumSchame(String biNameId, String targetSumId) {
	    boolean ok = statisticsBiSchameService.addTargetSumSchame(biNameId, targetSumId);
	    return ok;
      }

      @GetMapping("/getTargetSumSchameInfo")
      @AutoLog(
	      value = "获取单个计算指标配置信息",
	      operationType = OperationTypeEnum.SELECT,
	      module = "系统管理/配置表管理")
      public SysStatisticsTargetSum getTargetSumSchameInfo(String targetSumId) {
	    return statisticsBiSchameService.getTargetSumInfo(targetSumId);
      }


      @GetMapping("/getTargetSumList")
      @AutoLog(value = "获取计算指标列表", operationType = OperationTypeEnum.SELECT, module = "系统管理/配置表管理")
      public List<SysStatisticsTargetSum> getTargetSumList() {
	    return statisticsBiSchameService.getTargetSumList();
      }

      @PutMapping("/editTargetSum")
      @PreAuthorize("@Permission.hasPermi('bi_schame:edit')")
      @AutoLog(value = "更改计算指标", operationType = OperationTypeEnum.UPDATE, module = "系统管理/配置表管理")
      public boolean editTargetSum(@RequestBody SysStatisticsTargetSumUpdateInputVo targetSum) {
	    // TODO 需要删除 统计项和子项的所有数据
	    return statisticsBiSchameService.editTargetSum(targetSum);
      }

      @DeleteMapping("/removeTargetSumSchame")
      @PreAuthorize("@Permission.hasPermi('bi_schame:delete')")
      @AutoLog(value = "删除计算指标配置", operationType = OperationTypeEnum.DELETE, module = "系统管理/配置表管理")
      public boolean deleteSumTargetSchame(String targetSchameId) {
	    // TODO 需要删除 统计项和子项的所有数据
	    return statisticsBiSchameService.deleteTargetSchame(targetSchameId);
      }

      @PutMapping("/editCondition")
      @PreAuthorize("@Permission.hasPermi('bi_schame:edit')")
      @AutoLog(value = "更改部门信息", operationType = OperationTypeEnum.UPDATE, module = "系统管理/配置表管理")
      public boolean updateBiNameCondition(
	      @RequestBody SysStatisticsBiNameConditionUpdateVo inputVo) {

	    return statisticsBiSchameService.updateBiNameCondtion(inputVo);
      }

      @GetMapping("/getCondition")
      @AutoLog(value = "新增统计项", operationType = OperationTypeEnum.SELECT, module = "系统管理/配置表管理")
      public SysStatisticsBiName getBiNameCondition(String biNameId) {

	    return statisticsBiSchameService.getBiNameCondtion(biNameId);
      }
}
